package com.lht.testDemo;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class FormatReplaceTest {


    public static void main(String[] args) {

        Random random=new Random(100);
        List<String> replaceList=new ArrayList<>();
        for(int i=0;i<10000;i++){
            String str="";
            while(str.length()<100){
                if(str.length()==50){
                    str+="${hello}";
                }else{
                    str+=random.nextInt(10);
                }
            }
            replaceList.add(str);
        }

        List<String> formatList=new ArrayList<>();
        for(int i=0;i<10000;i++){
            String str="";
            while(str.length()<100){
                if(str.length()==50){
                    str+="%s";
                }else{
                    str+=random.nextInt(10);
                }
            }
            formatList.add(str);
        }

        Long starter=System.currentTimeMillis();

        for(String s:replaceList){
            s.replace("${hello}","hello");
        }
        Long end=System.currentTimeMillis();
        Long elapsed=end-starter;
        System.out.println("ReplaceTime:"+elapsed);


         starter=System.currentTimeMillis();

        for(String s:formatList){
            String.format(s,"hello");
        }
         end=System.currentTimeMillis();
         elapsed=end-starter;
        System.out.println("Format:"+elapsed);

    }


}
